import { getLocalStorage } from '@/utils'
import { accessTypeEnum } from '@/utils/enum'
import { history } from 'umi'

export const myGetInitialState = async (): Promise<initialStateProps> => {
  const models = {
    userModel: getLocalStorage('userModel'),
    tabsModel: getLocalStorage('tabsModel'),
  }

  let access: accessTypeEnum[] = []
  // if (models.userModel?.userPermissions?.permission) {
  //   const permission = JSON.parse(models.userModel.userPermissions.permission)
  //   access = [...permission.checked, ...permission.halfChecked]
  // } else {
  //   // message.error('登陆权限有误，返回登陆界面')
  //   history.push('/login')
  // }

  if (!init) return { access }
  init = false
  return {
    models,
    access,
  }
}
